package com.zzyl.controller.manager;

import com.aliyun.iot20180120.Client;
import com.aliyun.iot20180120.models.QueryDeviceDetailRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponse;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponseBody;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "Iot设备管理")
@RequestMapping("/iot")
public class DeviceController {

    @Autowired
    DeviceService deviceService;

    //TODO @ApiOperation("产品列表数据同步")
    @PostMapping("/syncProductList")
    public ResponseResult<Void> syncProductList() {
        log.info("同步产品列表数据");
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    //TODO @ApiOperation("查询所有产品列表")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct() {
        log.info("查询所有产品列表");
        List<ProductVo> list = deviceService.selectallProduct();
        return ResponseResult.success(list);
    }

    //TODO @ApiOperation("注册设备")
    @PostMapping("/RegisterDevice")
    public ResponseResult<Void> RegisterDevice(@RequestBody DeviceDto dto) {
        log.info("注册设备");
        deviceService.RegisterDevice(dto);
        return ResponseResult.success();
    }

    //TODO @ApiOperation("分页查询设备")
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageBean<DeviceVo>> pagequery(DevicePageQueryDto dto) {
        PageBean<DeviceVo> PageBean = deviceService.query(dto);
        return ResponseResult.success(PageBean);
    }

    //TODO @ApiOperation("查询设备详情")
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest deviceDetailRequest) {
        DeviceVo vo = deviceService.queryDeviceDetail(deviceDetailRequest);
        return ResponseResult.success(vo);
    }
    //============================================================== 课外作业

    //TODO @ApiOperation(value = "查看指定产品的物模型数据")
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> select(@RequestBody DeviceDto dto) {
        QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData vo = deviceService.selectid(dto);
        return ResponseResult.success(vo);
    }

    //TODO @ApiOperation(value = "查询指定设备的物模型运行状态")
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<DevicePropertyStatusVo> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        DevicePropertyStatusVo list = deviceService.queryDevicePropertyStatus(request);
        return ResponseResult.success(list);
    }

    //TODO @ApiOperation(value = "修改设备备注名称")
    @PostMapping("/UpdateDevice")
    public ResponseResult<Void> updateDevice(@RequestBody DeviceDto dto) {
        deviceService.updatedevice(dto);
        return ResponseResult.success();
    }

    //TODO @ApiOperation(value = "删除设备")
    @DeleteMapping("/DeleteDevice")
    public ResponseResult<Void> delete(@RequestBody DeviceDto dto) {
        deviceService.delete(dto);
        return ResponseResult.success();
    }
}
